package com.iamteer.b_ognl;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * 
 * @author Chuck
 *
 */
public class OgnlDemo2 extends ActionSupport{
	
	private User user = new User(100, "Jack");
	public void setUser(User user) {
		this.user = user;
	}
	public User getUser() {
		return user;
	}
	
	@Override
	public String execute() throws Exception {
		getVs();
		
		return "success";
	}

	// 一、获取值栈对象 2 种方式
	private void getVs() {
		// 获取值栈对象，方式 1：
		HttpServletRequest request = ServletActionContext.getRequest();
		ValueStack vs1 = (ValueStack) request.getAttribute("struts.valueStack");
		
		
		// 获取值廾对象，方式 2：
		ActionContext ac = ActionContext.getContext();
		ValueStack vs2 = ac.getValueStack();
		
		// 同一个对象
		System.out.println(vs1);
		System.out.println(vs2);
	}
}
